﻿using System;
using System.IO;

namespace ZhhbSoft.Data
{
    /// <summary>
    ///用于连接Microsoft Visual FoxPro 的 DbProvider
    /// </summary>
    public class MsVFoxProDbProvider : OdbcDbProvider
    {
        public MsVFoxProDbProvider()
            : this("")
        {
        }
        public MsVFoxProDbProvider(string strConnectionString)
        {
            if (strConnectionString == null)
            {
                OnError(new ArgumentNullException("strConnectionString"));
                return;
            }
            _strRawConnectionString = strConnectionString;
        }

        public override string CreateConnectionString(params string[] strItems)
        {
            return strItems == null || strItems.Length <= 0 || string.IsNullOrEmpty(strItems[0])
                       ? ""
                       : (File.Exists(strItems[0])
                              ? string.Format("Driver={{Microsoft Visual FoxPro Driver}};SourceType=DBF;SourceDB={0};Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO", strItems[0])
                              : (File.Exists(AppDomain.CurrentDomain.BaseDirectory + strItems[0])
                                     ? string.Format("Driver={{Microsoft Visual FoxPro Driver}};SourceType=DBF;SourceDB={0};Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO",
                                                     AppDomain.CurrentDomain.BaseDirectory + strItems[0])
                                     : strItems[0]));
        }
    }
}